/**
 * @param {number[]} rowSum
 * @param {number[]} colSum
 * @return {number[][]}
 */
var restoreMatrix = function(rowSum, colSum) {
  let arr = new Array(rowSum.length);
  for(let i = 0; i < arr.length; i++) {
    arr[i] = new Array(colSum);
  }
  for(let i = 0; i < rowSum.length; i++) {
    for(let j = 0; j < colSum.length; j++) {
      let value = Math.min(rowSum[i], colSum[j]);
      arr[i][j] = value;
      rowSum[i] -= value;
      colSum[j] -= value;
    }
  }
  return arr;
};
let rowSum = [3,8], colSum = [4,7];
console.log(restoreMatrix(rowSum, colSum));
rowSum = [5,7,10], colSum = [8,6,8];
console.log(restoreMatrix(rowSum, colSum));
rowSum = [14,9], colSum = [6,9,8];
console.log(restoreMatrix(rowSum, colSum));
rowSum = [1,0], colSum = [1];
console.log(restoreMatrix(rowSum, colSum));
rowSum = [0], colSum = [0];
console.log(restoreMatrix(rowSum, colSum));
